import java.util.Arrays; 
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		Person[] person=new Person[n];
		String name;
		int age;
		for (int i = 0; i <n; i++) {
			name=sc.next();
			age=sc.nextInt();		
			person[i]=new Person(name,age);
		}
		Arrays.sort(person);
		for (Person person2 : person) {
			System.out.println(person2);
			
		}
		System.out.println(Arrays.toString(Person.class.getInterfaces()));
		sc.close();
	}
}
class Person implements Comparable<Person>{
	private String name;
	private int age;
	
	public Person(String name,int age){
		this.name = name;
		this.age = age;
	}

	@Override
	public String toString() {
		return name+"-"+age;
	}
	@Override
	public int compareTo(Person o) {
		if(o instanceof Person){
			o=(Person) o;
		if(!this.name.equals(((Person)o).name)){
			if(this.name.compareTo(((Person)o).name)>0)
			return 1;
			else return -1;
		}
		else if(!(this.age==(((Person)o).age))){
			if(this.age>(((Person)o).age))
				return 1;
			else return -1;
		}
		
		return 0;
	}
		return 0;
	}
}